#ifndef __USART_H__
#define __USART_H__
#include "ft32f0xx.h"
#include "def.h"

#define BAUD 9600
#define SCANF_TIMEOUT 1000000UL
#define USART1_DMA_BUF_SIZE 256
//函数指针，当串口发生数据传输时产生该中断，传输参数为，当前数据的指针地址，数据包的长度
typedef void (*Type_OnDataReceived)(unsigned char*,unsigned int);
/*打印标准操作
初始化后，可使用printf,scanf,timeout_scanf，
*/
void usart_init(void);
void usart_deinit(void);
void usart_write(unsigned char *buffer, unsigned int counter);
GBool usart_isRxBufNotEmpty(void);
GBool usart_rxBufferTimeout(void);
#define USART_READBYTE() USART_ReceiveData(USART1);
void usart_rxReset(void);
void usart_idel_handler(void);//放置在中断函数中
void usart_dma_handler(void);//放置在中断函数中

//特别的scanf，会有超时效果，超时时间在上面，随便定的，只是用来倒数计时
#define timeout_scanf(format, ...)      \
    do                                  \
    {                                   \
        GBool ret = GFalse;             \
        ret = usart_rxBufferTimeout();  \
        if (!ret)                       \
        {                               \
            scanf(format, __VA_ARGS__); \
            usart_rxReset();            \
        }                               \
    } while (0)
extern Type_OnDataReceived OnDataReceived;
#endif




